<?php

class UserController extends Controller
{



    /*
     * 获取用户列表
     *
     */
    public function actionGetuserlist()
    {
        try
        {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //初始化
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql,"mobile","mobile"); //手机号

            //获取count
            $totalcount = UcUser::model()->count($searchsql);



            //排序
            $searchsql = $searchsql." order by user_id desc";
            //加上分页控制
            $searchsql = Util::addLimitSql($searchsql);

            //Util::responseMsg($searchsql);

            //获取list
            $userlist = UcUser::model()->findAll($searchsql);

            //去掉用户账户密码
            foreach($userlist as $key => $value) {
                $userlist[$key] = UserService::formatUser($userlist[$key]);
            }

            // Util::responseObj(MsgConst::RETURN_SUCCESS);
            Util::responseList($totalcount,$userlist);


        }catch (Exception $e)
        {

            Util::responseErrorMsg($e->getMessage());

        }
    }


    //轮播图

    /*
    * 获取列表
    *
    */
    public function actionGetCaroselList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();

            $type = Util::getParamNotEmpty("type");

            //获取列表
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql, "type", "type"); //手机号

            //排序
            $searchsql = $searchsql . " order by create_time ";
            //获取list
            $list = UcCarousel::model()->findAll($searchsql);

            Util::responseList(count($list), $list);


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 添加
    *
    */
    public function actionAddCarosel()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $pic_url = Util::getParamNotEmpty("pic_url");
            $link_url = Util::getParamNotEmpty("link_url");
            $title = Util::getParamNotEmpty("title");
            $type = Util::getParamNotEmpty("type");


            //添加
            $obj = new UcCarousel();
            Util::initObjData($obj);


            $obj->pic_url = $pic_url;
            $obj->link_url = $link_url;
            $obj->title = $title;
            $obj->type = $type;


            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 删除
    */
    public function actionDeleteCarosel()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");


            //删除
            $obj = UcCarousel ::model()->findByPK($obj_id);

                    Util::checkExistAndNotDelete($obj);

                    Util::deleteObjData($obj);

                    Util::saveObjData($obj);



                    //返回数据
                    Util::responseMsg(MsgConst::RETURN_SUCCESS);


                } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 修改
    *
    */
    public function actionUpdateCarosel()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");
            $pic_url = Util::getParamNotEmpty("pic_url");
            $link_url = Util::getParamNotEmpty("link_url");
            $title = Util::getParamNotEmpty("title");
            $type = Util::getParamNotEmpty("type");


            //验证存在
            $obj = UcCarousel::model()->findByPK($obj_id);

            Util::checkExistAndNotDelete($obj);

            //修改信息

            $obj->pic_url = $pic_url;
            $obj->link_url = $link_url;
            $obj->title = $title;
            $obj->type = $type;

            //保存
            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    //用户案例列表
    /*
    * 获取列表
    *
    */
    public function actionGetUserCaseList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();


            //参数列表
            $type_id = Util::getParamNotEmpty("type_id");


            //获取列表
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql, "type_id", "type_id"); //种类id

            //排序
            $searchsql = $searchsql . " order by create_time  desc";
            //获取list
            $list =UcCaselist ::model()->findAll($searchsql);


                //返回数据
                Util::responseList(count($list), $list);


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 添加
    *
    */
    public function actionAddUserCase()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $type_id = Util::getParamNotEmpty("type_id");
            $picurl = Util::getParamNotEmpty("picurl");
            $start_day = Util::getParamNotEmpty("start_day");
            $end_day = Util::getParamNotEmpty("end_day");
            $fee = Util::getParamNotEmpty("fee");
            $comment = Util::getParamNotEmpty("comment");
            $name = Util::getParamNotEmpty("name");


            //添加
            $obj = new UcCaselist();
            Util::initObjData($obj);


            $obj->type_id = $type_id;
            $obj->picurl = $picurl;
            $obj->start_day = $start_day;
            $obj->end_day = $end_day;
            $obj->fee = $fee;
            $obj->comment = $comment;
            $obj->name = $name;


            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 修改
    *
    */
    public function actionUpdateUserCase()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");

            $type_id = Util::getParamNotEmpty("type_id");
            $picurl = Util::getParamNotEmpty("picurl");
            $start_day = Util::getParamNotEmpty("start_day");
            $end_day = Util::getParamNotEmpty("end_day");
            $fee = Util::getParamNotEmpty("fee");
            $comment = Util::getParamNotEmpty("comment");
            $name = Util::getParamNotEmpty("name");


            //验证存在
            $obj = UcCaselist::model()->findByPK($obj_id);

            Util::checkExistAndNotDelete($obj);

            //修改信息

            $obj->type_id = $type_id;
            $obj->picurl = $picurl;
            $obj->start_day = $start_day;
            $obj->end_day = $end_day;
            $obj->fee = $fee;
            $obj->comment = $comment;
            $obj->name = $name;

            //保存
            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 删除
    */
    public function actionDeleteUserCase()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");


            //删除
            $obj = UcCaselist::model()->findByPK($obj_id);

                    Util::checkExistAndNotDelete($obj);

                    Util::deleteObjData($obj);

                    Util::saveObjData($obj);



                    //返回数据
                    Util::responseMsg(MsgConst::RETURN_SUCCESS);


                } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取案例种类列表
    *
    */
    public function actionGetUserCaseTypeList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();


            //获取列表
            $searchsql = Util::initSearchSql();

           // $searchsql = Util::getSerarchStr($searchsql, "mobile", "mobile"); //手机号

            //排序
            $searchsql = $searchsql . " order by create_time  desc";
            //获取list
            $list = UcCasekind ::model()->findAll($searchsql);


                //返回数据
                Util::responseList(count($list), $list);


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 添加用户案例的阶段
    *
    */
    public function actionAddUseCaseTask()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $case_id = Util::getParamNotEmpty("case_id");
            $name = Util::getParamNotEmpty("name");
            $worker_name = Util::getParamNotEmpty("worker_name");
            $days = Util::getParamNotEmpty("days");
            $material = Util::getParamNotEmpty("material");
            $piclist = Util::getParamNotEmpty("piclist");

            $testor_name = Util::getParamNotEmpty("testor_name");
            $testpiclist = Util::getParamNotEmpty("testpiclist");
            $test_content = Util::getParamNotEmpty("test_content");





            //case
            $caseobj = UcCaselist::model()->findByPK($case_id);
            Util::checkExistAndNotDelete($caseobj);

            //添加
            $obj = new UcCasetask();
            Util::initObjData($obj);


            $obj->case_id = $case_id;
            $obj->name = $name;
            $obj->worker_name = $worker_name;
            $obj->days = $days;
            $obj->material = $material;
            $obj->piclist = $piclist;

            $obj->testor_name = $testor_name;
            $obj->testpiclist = $testpiclist;
            $obj->test_content = $test_content;


            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 修改
    *
    */
    public function actionUpdateUserCaseTask()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");
            $name = Util::getParamNotEmpty("name");
            $worker_name = Util::getParamNotEmpty("worker_name");
            $days = Util::getParamNotEmpty("days");
            $material = Util::getParamNotEmpty("material");
            $piclist = Util::getParamNotEmpty("piclist");

            $testor_name = Util::getParamNotEmpty("testor_name");
            $testpiclist = Util::getParamNotEmpty("testpiclist");
            $test_content = Util::getParamNotEmpty("test_content");


            //验证存在
            $obj = UcCasetask::model()->findByPK($obj_id);

            Util::checkExistAndNotDelete($obj);

            //修改信息

            $obj->name = $name;
            $obj->worker_name = $worker_name;
            $obj->days = $days;
            $obj->material = $material;
            $obj->piclist = $piclist;

            $obj->testor_name = $testor_name;
            $obj->testpiclist = $testpiclist;
            $obj->test_content = $test_content;

            //保存
            Util::saveObjData($obj);


            //返回数据
            Util::responseMsg(MsgConst::RETURN_SUCCESS);


        } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 删除
    */
    public function actionDeleteUserCaseTask()
    {

        try {
            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $obj_id = Util::getParamNotEmpty("obj_id");


            //删除
            $obj = UcCasetask ::model()->findByPK($obj_id);

                    Util::checkExistAndNotDelete($obj);

                    Util::deleteObjData($obj);

                    Util::saveObjData($obj);



                    //返回数据
                    Util::responseMsg(MsgConst::RETURN_SUCCESS);


                } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
    * 获取任务列表
    *
    */
    public function actionGetUserCaseTaskList()
    {
        try {
            //参数验证

            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $case_id = Util::getParamNotEmpty("case_id");


            //获取列表
            $searchsql = Util::initSearchSql();

            $searchsql = Util::getSerarchStr($searchsql, "case_id", "case_id"); //手机号

            //排序
            $searchsql = $searchsql . " order by create_time  ";

            //获取list
            $list = UcCasetask::model()->findAll($searchsql);


            //返回数据
            Util::responseList(count($list), $list);


            } catch (Exception $e) {
            Util::responseErrorMsg($e->getMessage());

        }
    }


}